﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.Utilities;
using NetDon.WebControls;
using NetDon.eBoss.Data.CollectionClasses;
using NetDon.eBoss.Data.EntityClasses;
using NetDon.eBoss.Data.HelperClasses;
using NetDon.eBoss.Portal.HtmlTool;

namespace NetDon.OA.Portal.HtmlTool
{
    public partial class TrademarkManagement : NetDonPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            PageQueryAdapter1.PageSize = 100;
            if (!IsPostBack)
            {

                PageQueryAdapter1.PerformQuery();

            }
        }


        protected void PageQueryAdapter1_PerformGetCondition(object sender, PerformGetConditionEventArgs e)
        {
            var criteria = new TrademarkCriteria
            {
                Name = txtTrademark.Text.Trim(),

            };

            e.Condition = criteria;
        }

        public void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            PageQueryAdapter1.PerformQuery();



        }
        protected void PageQueryAdapter1_PerformGetRecordCount(object sender, PerformGetRecordCountEventArgs e)
        {
            e.RecordCount = new HtmlToolService().GetTrademarkCount((TrademarkCriteria)e.Condition);
        }

        protected void PageQueryAdapter1_PerformGetPageData(object sender, PerformGetPageDataEventArgs e)
        {

            e.DataSource = new HtmlToolService().SearchTrademarkByCondition((TrademarkCriteria)e.Condition, gridCustomerInfoList.SortExpression,
                                                      gridCustomerInfoList.SortDirection, e.PageSize, e.PageIndex);
        }

        protected void btnReload_Click(object sender, EventArgs e)
        {
            PageQueryAdapter1.PerformQuery();
        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            PageQueryAdapter1.PerformQuery();
        }

        protected void gridOrderList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var entity = (e.Row.DataItem);

                var orderId = e.Row.Attributes["Id"] = Convert.ToString(DataBinder.Eval(entity, "Id"));


            }
        }
        protected void btnDeleteDemand_Click(object sender, EventArgs e)
        {

            var customerId = fieldCustomerId.Value.ToInt32();

            //check if used by product description
            var collection = new ProductgroupCollection();
            collection.GetMulti(ProductgroupFields.Trademarkid == customerId);
            if(collection.Count >0)
            {
                Alert("不可以删除。商品描述正在使用该品牌");
                return;
            }
            bool result = new HtmltooltrademarksettingEntity(customerId.Value).Delete();

            if (result)
            {
                PageQueryAdapter1.PerformQuery();
                Alert("删除成功!");
            }
            else
            {
                Alert("删除失败！");
            }
        }


 


    }
}